package com.fosss.band.controller;

import com.fosss.band.entity.Band;
import com.fosss.band.entity.Member;
import com.fosss.band.entity.dto.BandDto;
import com.fosss.band.entity.vo.BandVo;
import com.fosss.band.entity.vo.MemberVo;
import com.fosss.band.service.BandService;
import com.fosss.band.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: fosss
 * Date: 2023/12/31
 * Time: 15:19
 * Description:
 */
@Slf4j
@Api(tags = "乐队相关接口")
@RestController
@RequestMapping("/band")
public class BandController {

    @Resource
    private BandService bandService;

    @ApiOperation("分页查询乐队信息")
    @GetMapping("/getBandListPage/{userId}/{page}/{size}")
    public Result getBandListPage(@PathVariable("userId") Integer userId,
                                  @PathVariable("page") Integer page,
                                  @PathVariable("size") Integer size,
                                  @RequestParam(value = "name", required = false) String name) {
        log.info("分页查询乐队信息");
        return bandService.getBandListPage(userId, page, size, name);
    }

    @ApiOperation("删除乐队")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable("id") Integer id) {
        log.info("删除乐队：{}", id);
        return bandService.removeById(id);
    }

    @ApiOperation("新增乐队")
    @PostMapping("/add")
    public Result add(@RequestBody BandVo bandVo) {
        log.info("新增乐队：" + bandVo);
        return bandService.add(bandVo);
    }

    @ApiOperation("查询单个乐队")
    @GetMapping("/getBandById/{id}")
    public Result getBandById(@PathVariable("id") Integer id) {
        log.info("查询单个乐队");
        return bandService.getBandById(id);
    }

    @ApiOperation("根据乐队id查询成员")
    @GetMapping("/getMemberByBandId/{bandId}")
    public Result selectMembers(@PathVariable("bandId") Integer bandId) {
        log.info("根据乐队id查询成员");
        return bandService.getMembersByBandId(bandId);
    }

    @ApiOperation("更新乐队信息")
    @PutMapping("/updateBand")
    public Result updateBand(@RequestBody Band band) {
        log.info("更新乐队信息");
        return bandService.updateBand(band);
    }

    @ApiOperation("删除成员")
    @DeleteMapping("/deleteMember/{id}")
    public Result deleteMember(@PathVariable("id") Integer id) {
        log.info("删除成员");
        return bandService.deleteMember(id);
    }

    @ApiOperation("查询成员信息")
    @GetMapping("/selectMember/{id}")
    public Result selectMember(@PathVariable("id") Integer id) {
        log.info("查询成员信息");
        return bandService.selectMember(id);
    }

    @ApiOperation("编辑成员")
    @PutMapping("/updateMember")
    public Result updateMember(@RequestBody MemberVo memberVo) {
        log.info("编辑成员");
        return bandService.updateMember(memberVo);
    }

    @ApiOperation("添加成员")
    @PostMapping("/addMember")
    public Result addMember(@RequestBody MemberVo memberVo) {
        log.info("添加成员：{}", memberVo);
        return bandService.addMember(memberVo);
    }

    @ApiOperation("查询所有乐队")
    @GetMapping("/selectAll")
    public Result selectAll() {
        log.info("查询所有乐队");
        return bandService.selectAll();
    }
}


















